<?php
!defined('P_W') && exit('Forbidden');
/**
 * 
 * 二手房服务基类
 * @author hu.liaoh
 *
 */
class PW_SecondBaseService{

	function PW_SecondBaseService(){
	}
	
	/**
	 *
	 * 过期房源定期更新处理
	 * @param $expiredType
	 * @param $houseids
	 */
	function updateExpired($expiredType, $houseids){
		switch ($expiredType){
			case 'expired' ://房源
				$this->setState($houseids, 2);
				break;
			case 'urgent'://加急
				$this->setUrgent($houseids, 0);
				break;
			case 'top': //置顶
				$this->setTop($houseids, 0);
				break;
			default:
				break;
		}
	}
	
	/**
	 * 
	 * 获取相近房源
	 * @param $houseid 房源id 
	 * @param $areatype 区域类型
	 * @param $price 价格
	 * @param $limit 数量
	 */
	function getSimilarList($houseid, $areatype, $price, $limit = 5){
		$infoDB = $this->_getInfoDB();	//从DB中取出数据
		$result = $infoDB->getSimilarList($houseid, $areatype, $price, $limit);
		return $this->_getDetailInfo($result);
	}
	
	/**
	 *
	 * 获取多条房源信息
	 * @param $houseids
	 */
	function getSecondInfos($houseids){
		$houseids = $this->_filterHouseids($houseids);
		$infoDB = $this->_getInfoDB();	//从DB中取出数据
		$result = $infoDB->gets($houseids);
		return $this->_getDetailInfo($result);
	}
	
	/**
	 *
	 * 刷新房源
	 * @param $houseids
	 */
	function refresh($houseids){
		global  $timestamp;
		$infoDB = $this->_getInfoDB();
		$infoDB->update(array('modifytime'=>$timestamp), $houseids);	//更新详细信息表中的数据
		$modifyTimeDB = $this->_getModifytimeDB();
		$modifyTimeDB->update(array('modifytime'=>$timestamp), $houseids);
		return true;
	}
	
	/**
	 * 
	 * 重新发布房源
	 * @param $houseid
	 */
	function republish($houseid){
		global  $timestamp;
		$this->setState($houseid,0);
		$infoDB = $this->_getInfoDB();
		$infoDB->update(array('posttime'=>$timestamp), $houseid);	//更新详细信息表中的数据
		$this->_addExpired($houseid);
		$postTimeDB = $this->_getPosttimeDB();
		$postTimeDB->update(array('posttime'=>$timestamp), $houseid);
		return true;
	}

	/**
	 *
	 * 对二手房住处进行 输入｜输出 适配
	 * @param $secondInfo
	 * @param $direct in-将文字转换成枚举 ,out-将枚举转换成文字
	 */
	function adapterSecondInfo($secondInfo, $direct='in'){
		if($direct == 'in')	$secondInfo = $this->_checkInput($secondInfo);//对输入数据内容进行安全过滤及枚举转换
		if($direct == 'out') $secondInfo = $this->_checkOutput($secondInfo);//对输出数据内容进行枚举转换
		return $secondInfo;
	}
	
	/**
	 *
	 * 获取二手房信息列表
	 * @param $where_array where 索引数组array(areatype,pricetype,fitmenttype,roomtype,hiretype);
	 * @param $keywords 关键字数组
	 * @param $sort 排序方式[DESC,ASC]
	 * @param $offset 分页开始值
	 * @param $limit 分页偏移量
	 * @param $orderType 排序类型
	 */
	function getList($arrayIndex, $sort, $sortField,$keywords, $offset, $limit, $expand=array()){
		$hireDB = $this->_getSecondDB();
		$sortField = $this->_filterOrders($sortField);
		return $hireDB->getList($arrayIndex, $sort, $sortField, $keywords, $offset, $limit, $expand);
	}

	/**
	 * 
	 * 获房源的详细信息列表
	 * @param $where_array where 索引数组array(areatype,pricetype,fitmenttype,roomtype,hiretype);
	 * @param $keywords 关键字数组
	 * @param $sort 排序方式[DESC,ASC]
	 * @param $offset 分页开始值
	 * @param $limit 分页偏移量
	 * @param $orderType 排序类型
	 */
	function getDetailList($arrayIndex, $sort, $sortField,$keywords, $page, $limit, $expand=array()){
		list($total,$rt) = $this->getList($arrayIndex, $sort, $sortField, $keywords, $page, $limit, $expand);
		$result = $this->_getDetailInfo($rt);
		return array($total, $result);
	}
	
	/**
	 * 
	 * 更新房源状态
	 * @param $houseids 房源id
	 * @param $state 状态 0表示正常，1表示下架，2表示过期
	 */
	function setState($houseids,$state){
		$infoDB = $this->_getInfoDB();
		!$state ? $this->_overdueToNomal($houseids) : $this->_nomalToOverdue($houseids);
		return $infoDB->setState($houseids,$state);
	}
	
	/**
	 * 
	 * 加急处理
	 */
	function setUrgent($houseids, $value, $days=0, $isback=0, $ismsg=0){
		return $this->_setHandler($houseids, 'urgent',$value, $days, $isback, $ismsg);
	}
	
	/**
	 * 
	 * 置顶处理
	 */
	function setTop($houseids, $value, $days=0, $isback=0, $ismsg=0){
		return $this->_setHandler($houseids, 'top',$value, $days, $isback, $ismsg);
	}
	/**
	 * 
	 * 根据值取出字段对应的文字
	 * @param $type
	 */
	function getFieldsByType($type){
		$HouseFields = $this->_getFieldsService();
		$fieldtype = $HouseFields->getFieldType($type);
		$fields = $HouseFields->getAllFieldListByType($type);
		$tmpdata = array();
		foreach ($fields as $key=>$value){
			$tmpdata[$key] = ($fieldtype == 'range') ? $value['value'] : $value['name'];
		}
		return $tmpdata;
	}
	
	/**
	 * 
	 * 获取非经纪人信息
	 * @param $houseid
	 */
	function getPersonInfo($houseid){
		$personalDB = $this->_getPersonalDB();
		return $personalDB->get($houseid);
	}
	
	/**
	 * 
	 * 根据houseid查找用户id
	 * @param $houseids
	 */
	function getUidsByHouseid($houseids){
		$houseids= $this->_filterHouseids($houseids);
		$infoDB = $this->_getInfoDB();
		return $infoDB->getUidsByHouseid($houseids);
	}
	
	/**
	 * 
	 * 根据区域id获取版块
	 * @param $areaId
	 */
	function getPlateByAreaId($areaId){
		$fieldService = $this->_getFieldsService();
		return $fieldService->getPlateByAreaId($areaId);
	}
	
	function _getSecondMap(){}
	function _addSecondNum($uid,$num){}
	function _overdueToNomal($houseids){}
	function _nomalToOverdue($houseids){}
	function _checkInput($secondInfo){}
	function _checkOutput($secondInfo){}
	function _getInfoDB(){}
	function _getOverdueDB(){}
	function _getSecondDB(){}
	function _getPersonalDB(){}
	function _getPosttimeDB(){}
	function _getModifytimeDB(){}
	function _getPriceDB(){}
	
	/**
	 * 
	 * 加急 置顶房源操作
	 * @param $secondType 房源类型 sale,hire
	 * @param $houseids 房源id
	 * @param $type 操作类型 'urgent','top'
	 * @param $value 操作结果 1 表示 是， 0表示 非
	 * @param $days 加急｜置顶的天数
	 * @param $isback 是否返回用户积分
	 * @param $ismsg 是否发送消息
	 */
	function _setHandler($houseids, $type, $value, $days=0, $isback=0, $ismsg=0){
		$secondType = $this->_secondType;
		if(!in_array($type, array('urgent', 'top'))) return false;
		$infoDB = $this->_getInfoDB();
		$value = intval($value);
		!S::isArray($houseids) && $houseids = array($houseids);
		$retv = $infoDB->setHandler($houseids, $type, $value);//更新房源状态
		if($value && $days) $this->_upTopOrUrgent($houseids, $days, $type, $ismsg); //加急置顶操作
		if(!$value) $this->_downTopOrUrgent($houseids, $type, $isback, $ismsg); //取消加急置顶操作
		if($type == 'top')	$this->_updateConfig();//更新置顶房源到缓存文件
		return $retv;
	}
	
	function _addExpired($houseid){
		$secondType = $this->_secondType;
		global $timestamp;
		$Expired = $this->_getExpiredService();
		$Expired->addExpired($secondType,'expired',$houseid,$timestamp + ((int)$GLOBALS['house_'.$secondType.'_expried']) * 86400);//增加一条记录到过期时间表中
	}
	
	/**
	 * 
	 * 加急置顶操作
	 * @param $houseids 房源id
	 * @param $type 操作类型 'urgent','top'
	 * @param $ismsg 是否发送消息
	 */
	function _upTopOrUrgent($houseids, $days, $type, $ismsg){
		global $timestamp;
		$infoDB = $this->_getInfoDB();
		$secondType = $this->_secondType;
		$Expired = House::LoadService('ExpiredService');
		$infos = $infoDB->getUserInfoByHouseid($houseids); //获取房源对应的联系人信息
		$typeArr= array(top=>'置顶','urgent'=>'加急');
		foreach ($houseids as $houseid)	{
			$expireInfo = $Expired->getsExpire($houseid, $secondType, $type);
			$expiredtime = $expireInfo[$houseid]['expiredtime'] ? $expireInfo[$houseid]['expiredtime'] : $timestamp;//如果已经加急再加急操作
			$endTime = ((int)$expiredtime + $days * 86400);
			$Expired->addExpired($secondType,$type, $houseid, $endTime);
			$ismsg && M::sendNotice(array($infos[$houseid]['username']), array('title'=>'房源' . $typeArr[$type] . '成功', 'content'=>$GLOBALS['windid'] . '对您的房源“'.$infos[$houseid]['subject'].'”进行了'. $typeArr[$type] .'操作。'. $typeArr[$type] .'至' . date('Y-m-d',$endTime) . '。'));//发送消息到房源发布者
		}
	}
	
	/**
	 * 
	 * 加急 置顶房源操作
	 * @param $houseids 房源id
	 * @param $type 操作类型 'urgent','top'
	 * @param $isback 是否返回用户积分
	 * @param $ismsg 是否发送消息
	 */
	function _downTopOrUrgent($houseids, $type, $isback, $ismsg){
		$Expired = House::LoadService('ExpiredService');
		$this->_creditAndSendMsg($houseids, $type, $isback, $ismsg);//是否 归还积分、发送消息操作
		foreach ($houseids as $houseid)	{//删除过期信息表中的数据
			$Expired->deleteHouseExpires( $this->_secondType,$type ,$houseid);
		}
	}
	/**
	 * 
	 * 积分 操作和发送消息 
	 * @param $houseids 房源id
	 * @param $type 类型 top、urgent
	 * @param $isback 是否退还积分
	 * @param $ismsg 是否发送消息
	 */
	function _creditAndSendMsg($houseids, $type, $isback, $ismsg){
		if(!in_array($type, array('top','urgent'))) return false;
		$infoDB = $this->_getInfoDB();
		$infos = $infoDB->getUserInfoByHouseid($houseids);
		$expriedService = $this->_getExpiredService();
		$extrieds = $expriedService->getsExpire($houseids, $this->_secondType, $type);
		$tmp = array();
		foreach($infos as $key=>$value){
			if($extrieds[$key]['expiredtime'] && $infos[$key]['uid']){
				$tmp[$key]['expiredtime'] = $extrieds[$key]['expiredtime'];
				$tmp[$key]['uid'] = $infos[$key]['uid'];
				$tmp[$key]['subject'] = $infos[$key]['subject'];
				$tmp[$key]['username'] = $infos[$key]['username'];
			}
		}
		$this->_doCreditAndSendMsg($tmp, $type, $isback, $ismsg);
	}
	
	/**
	 * 
	 * 退出积分和发送消息 
	 * @param $tmp
	 * @param $type
	 * @param $isback
	 * @param $ismsg
	 */
	function _doCreditAndSendMsg($tmp, $type, $isback, $ismsg){
		global $timestamp;
		$secondType = $this->_secondType;
		require_once(R_P.'require/credit.php');
		include(D_P.'data/bbscache/house_config.php');
		
		$price = ($type == 'urgent') ? ${'house_' .$secondType. '_rapidprice'} : ${'house_' . $secondType . '_topprice'};
		$creditType = ($type == 'urgent') ? ${'house_' .$secondType. '_rapidcredit'} : ${'house_' .$secondType. '_topcredit'};
		$creditname = $credit->cType[$creditType];
		$typeArr= array(top=>'置顶','urgent'=>'加急');
		foreach($tmp as $key=>$value){
			$d = ceil(($value['expiredtime'] - $timestamp)/86400);
			$isback && $credit->set($value['uid'], $type, +($d * $price));
			$ismsg && M::sendNotice(array($value['username']), array('title'=>'房源'. $typeArr[$type] .'已被取消', 'content'=>'您'. $typeArr[$type] .'的房源“'. $value['subject'] .'”已经被管理员'. $GLOBALS['windid'] .'取消。已退还'. $d * $price . $creditname .'。'));
		}
	}
	
	/**
	 * 
	 * 获取置顶的房源和houseid
	 */
	function _getTopHouseids(){
		$infoDB = $this->_getInfoDB();
		return $infoDB->getTopHouseids();
	}
	
	/**
	 * 
	 * 检查houseid
	 * @param unknown_type $houseids
	 */
	function _filterHouseids($houseids){
		!is_array($houseids) && $houseids = array($houseids);
		foreach($houseids as $key=>$value){
			if(empty($value) || $value == '') unset($houseids[$key]);
		}
		return $houseids;
	}
	
	/**
	 * 
	 * 保存配置
	 * @param $houseids
	 */
	function _updateConfig(){
		$tmp = array();
		$tops = $this->_getTopHouseids();
		$config['house_' . $this->_secondType] = $tops;
		$this->_cacheConfig($config);
	}
	
	/**
	 * 
	 * 更新缓存
	 * @param $config
	 */
	function _cacheConfig($config){
		require_once R_P.'admin/cache.php';
		foreach ($config as $key => $value) {
			setConfig($key, $value, null, true);
		}
		updatecache_conf('house', true);
	}
	
	/**
	 *
	 * 从module中获取数据
	 * @param $hireModule
	 */
	function _moduleToArray($secondModule){
		$tmp = array();
		$map = $this->_getSecondMap();
		foreach($map as $field=>$value){
			$tmp[$field] = $secondModule->{$value};
		}
		return $tmp;
	}

	/**
	 *
	 * 根据一个数据返回module
	 * @param $data
	 * @param $hireModule
	 */
	function _arrayToModule($data, $secondModule){
		$map = $this->_getSecondMap();
		foreach ($map as $field=>$value){
			$secondModule->{$value} = $data[$field];
		}
		$room = str_split($data['room']);
		$secondImageService = $this->_getImageService();
		$secondModule->attachs = $secondImageService->getByHouseId($data['houseid'], $this->_secondType);
		$secondModule->room = array('bedroom'=>$room[0], 'hall'=>$room[1], 'toilet'=>$room[2], 'terrace'=>$room[3]);
		if(!checkBroker($secondModule->uid)){
			$personal = $this->getPersonInfo($data['houseid']);
			$secondModule->linkman = $personal['linkman'];
			$secondModule->phone = $personal['phone'];
			$secondModule->tel = $personal['tel'];
			$secondModule->email = $personal['email'];
		}
		return $secondModule;
	}
	
	/**
	 * 
	 * 添加房源图片
	 * @param $houseid
	 * @param $data
	 */
	function _addImage($houseid, $data){
		$tmp = array();
		foreach ($data['attachs'] as $key=>$value){
			$value['houseid'] = $houseid;
			$tmp[] = $value;
		}
		$uploadService = $this->_getImageService();
		return $uploadService->uploadUpdate($tmp, $this->_secondType);
	}
	
	/**
	 *
	 * 更新房源图片
	 */
	function _updateImage($houseid, $data){
		$attachs = $this->_modifyAttchsPath($data['attachs']);
		$uploadService = $this->_getImageService();
		foreach ($attachs as $key=>$value){
			switch ($value['attname']){
				case 'replace':
					$value['type'] = $this->_secondType;
					$uploadService->update($value['imageid'], $value);
					break;
				case 'delete':
					$uploadService->delete($value['imageid']);
					break;
				default:
					$value['houseid'] = $houseid;
					$uploadService->uploadUpdate(array($value), $this->_secondType);
					break;
			}
		}
	}
	
	/**
	 * 修改图片
	 * @param array $attachs
	 * @return array $attachs
	 */
	function _modifyAttchsPath($attachs){
		foreach($attachs as $key => $value){
			if($value['id'] && $value['attname'] != 'attachment'){
				 $tempPath = $attachs[$value['id']]['path'];
				 $attachs[$value['id']]['path'] = $value['fileuploadurl'];
				 $attachs[$value['id']]['uploadtime'] = $value['uploadtime'];
				 $attachs[$value['id']]['ext'] = $value['ext'];
				 $attachs[$value['id']]['size'] = $value['size'];
				 $this->_deleteOldImage($tempPath);
				 unset($attachs[$key]);
			}
		}
		return $attachs;
	}
	
	/**
	 * 删除旧图片
	 * @param string $path
	 */
	function _deleteOldImage($path) {
		$thumbPath = str_replace('salepic/', 'salethumbpic/', $path);
		is_file($path) && P_unlink($path);
		is_file($thumbPath) && P_unlink($thumbPath);	
	}
	
	/**
	 * 
	 * 获取房源图片结果集
	 * @param $houseid
	 */
	function _getImage($houseid, $type){
		$uploadService = $this->_getImageService();
		$result = $uploadService->getByHouseId($houseid, $type);
		return $result;
	}
	
	/**
	 *
	 * 增加详细信息表中的数据
	 * @param $secondInfo 房源信息
	 */
	function _addSecondInfo($secondInfo){
		$infoDB = $this->_getInfoDB();
		$infoData = $this->_filterField($secondInfo, $infoDB->getStruct('add'));
		$retV = $infoDB->add($infoData);
		if(!S::isnum($retV)) return false;
		return $retV;
	}

	/**
	 *
	 * 更新详细信息表中的数据
	 * @param $secondInfo
	 */
	function _updateSecondInfo($secondInfo, $houseids){
		$infoDB = $this->_getInfoDB();
		$infoData = $this->_filterField($secondInfo,$infoDB->getStruct('update'));
		$retV = $infoDB->update($infoData, $houseids);
		if($retV == false) return false;
	}
	/**
	 *
	 * 增加发布时间索引表中的数据
	 * @param $secondInfo房源信息
	 */
	function _addPostTime($secondInfo){
		$postTimeDB = $this->_getPosttimeDB();
		$postTimeData = $this->_filterField($secondInfo, $postTimeDB->getStruct('add'));
		$retV = $postTimeDB->add($postTimeData);
		if(!S::isnum($retV)) return false;
		return $retV;
	}

	/**
	 *
	 * 增加修改时间索引表中的数据
	 * @param $secondInfo房源信息
	 */
	function _addModifyTime($secondInfo){
		$modifyTimeDB = $this->_getModifytimeDB();
		$modifyTimeData = $this->_filterField($secondInfo, $modifyTimeDB->getStruct('add'));
		$retV = $modifyTimeDB->add($modifyTimeData);
		if(!S::isnum($retV)) return false;
		return $retV;
	}

	/**
	 *
	 * 增加总售价索引表中的数据
	 * @param $secondInfo房源信息
	 */
	function _addPrice($secondInfo){
		$priceDB = $this->_getPriceDB();
		$priceData = $this->_filterField($secondInfo, $priceDB->getStruct('add'));
		$retV = $priceDB->add($priceData);
		if(!S::isnum($retV)) return false;
		return $retV;
	}
	/**
	 *
	 * 更新修改时间索引表中的数据
	 * @param $secondInfo房源信息
	 */
	function _updateModityTime($secondInfo, $houseids){
		$modifyTimeDB = $this->_getModifytimeDB();
		$modifyTimeData = $this->_filterField($secondInfo,$modifyTimeDB->getStruct('update'));
		$retV = $modifyTimeDB->update($modifyTimeData, $houseids);
		if($retV == false) return false;
	}
	
	/**
	 *
	 * 更新修改时间索引表中的数据
	 * @param $secondInfo房源信息
	 */
	function _updatePostTime($secondInfo, $houseids){
		$postTimeDB = $this->_getPosttimeDB();
		$postTimeData = $this->_filterField($secondInfo,$postTimeDB->getStruct('update'));
		$retV = $postTimeDB->update($postTimeData, $houseids);
		if($retV == false) return false;
	}

	/**
	 *
	 * 更新总售价索引表中的数据
	 * @param $secondInfo房源信息
	 */
	function _updatePrice($secondInfo, $houseids){
		$priceDB = $this->_getPriceDB();
		$priceData = $this->_filterField($secondInfo,$priceDB->getStruct('update'));
		$retV = $priceDB->update($priceData, $houseids);
		if($retV == false) return false;
	}
	
	/**
	 *
	 * 删除详细信息表中的数据
	 * @param $houseids房源IDS
	 */
	function _deleteSecondInfo($houseids){
		$infoDB = $this->_getInfoDB();
		$retV = $infoDB->delete($houseids);
		if($retV == false) return false;
	}

	/**
	 *
	 * 删除修改时间索引表中的数据
	 * @param $houseids房源IDS
	 */
	function _deleteModifyTime($houseids){
		$modifyTimeDB = $this->_getModifytimeDB();
		$retV = $modifyTimeDB->delete($houseids);
		if($retV == false) return false;
	}

	/**
	 *
	 * 删除发布时间索引表中的数据
	 * @param $houseids房源IDS
	 */
	function _deletePostTime($houseids){
		$postTimeDB = $this->_getPosttimeDB();
		$retV = $postTimeDB->delete($houseids);
		if($retV == false) return false;
	}

	/**
	 *
	 * 删除总售价索引表中的数据
	 * @param $houseids房源IDS
	 */
	function _deletePrice($houseids){
		$priceDB = $this->_getPriceDB();
		$retV = $priceDB->delete($houseids);
		if($retV == false) return false;
	}
	
	function _deletePersonal($houseids){
		$type = $this->getDataType($this->_secondType);
		$personalDB = $this->_getPersonalDB();
		$retV = $personalDB->delete($houseids, $this->_secondType);
		if($retV == false) return false;
	}
	/**
	 * 
	 * 删除房源过期信息表
	 */
	function _deleteExpired($houseids){
		$expired = $this->_getExpiredService();
		$retV = $expired->deleteAllHouseExpires($this->_secondType,$houseids);
		if($retV == false) return false;
	}
	
	/**
	 *
	 * 根据范围获取对应字段的ID
	 * @param unknown_type $type
	 * @param unknown_type $value
	 */
	function _getIdFromRange($type,$value){
		$HouseFields = $this->_getFieldsService();
		$fields = $HouseFields->getAllFieldListByType($type);
		if(!is_array($fields)) return 0;
		foreach ($fields as $key=>$v){
			if($v['end'] == 0 && $value >= $v['start']){
				return $key; break;
			}
			if($value >= $v['start'] && $value<= $v['end']){
				return $key; break;
			}
		}
		return 0;
	}
	/**
	 * 
	 * 获取一条房源的详细信息
	 * @param $rt
	 */
	function _getDetailInfo($rt){
		if(!is_array($rt)) return array();
		$result = array();
		foreach ($rt as $value){//适配返回信息
			$result[] = $this->adapterSecondInfo($value ,'out');
		}
		return $result;
	}
	
	/**
	 *
	 * 根据结构过滤字段数据
	 * @param $data
	 * @param $struct
	 */
	function _filterField($data, $struct){
		$temp = array();
		foreach($struct as $field){
			isset($data[$field]) && $temp[$field] = $data[$field];
		}
		return $temp;
	}
	
	/**
	 * 
	 * 添加个人信息
	 * @param $secondInfo
	 */
	function _addPersonal($secondInfo, $type){
		$secondInfo['datatype'] = $this->getDataType($type);
		$personalDB = $this->_getPersonalDB();
		$infoData = $this->_filterField($secondInfo, $personalDB->getStruct('add'));
		$retV = $personalDB->add($infoData, $type);
		if(!S::isnum($retV)) return false;
		return $retV;
	}
	
	function getDataType($type){
		$data = array_flip(array(1=>'sale', 2=>'hire'));
		return $data[$type] ? $data[$type] : 0;
	}
	/**
	 * 
	 * 添加个人信息
	 * @param $secondInfo
	 */
	function _updatePersonal($secondInfo, $houseids){
		$personalDB = $this->_getPersonalDB();
		$infoData = $this->_filterField($secondInfo, $personalDB->getStruct('update'));
		$retV = $personalDB->update($infoData, $houseids);
		if(!S::isnum($retV)) return false;
		return $retV;
	}
	
	/**
	 * 
	 * 更新用户发布数量
	 * @param $houseids
	 */
	function _updateSecondNums($houseids) {
		$infoDB = $this->_getInfoDB();
		$uids = $infoDB->getUidsByHouseid($houseids);
		foreach ($uids as $uid) {
			$this->_addSecondNum($uid, -1);
		}
	}
	
	/**
	 * 
	 * 删除房源过期信息表
	 */
	function _deleteImage($houseids){
		$imageService = $this->_getImageService();
		$retV = $imageService->deleteByHidsAndType($houseids, $this->_secondType);
		if($retV == false) return false;
	}

	/**
	 * 
	 * 删除过期索引表中数据
	 * @param $houseids
	 */
	function _deleteOverdue($houseids){
		$overdueDB = $this->_getOverdueDB();
		$retV = $overdueDB->delete($houseids);
		if($retV == false) return false;
	}
	
	/**
	 *
	 * 过滤排序方式，默认为按修改时间排序
	 * @param $orderType 排序方式
	 */
	function _filterOrders($orderType){
		return in_array($orderType, $this->_orderTypes) ? $orderType : 'modifytime';
	}
	/**
	 * 
	 * 获取经纪人服务类
	 */
	function _getBrokerService(){
		return House::LoadService('BrokerService');
	}
	/**
	 *
	 * 获取字段服务类
	 */
	function _getFieldsService(){
		return House::LoadService('HouseFieldsService');
	}
	/**
	 *
	 * 获取图片上传服务
	 */
	function _getImageService(){
		return House::LoadService('SecondimageService');
	}
	/**
	 * 
	 * 获取过期信息表服务类
	 */
	function _getExpiredService(){
		return House::LoadService('ExpiredService');
	}
}